﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;

namespace CommonUtils.Web.Test.apis
{
    [Route("api/[controller]/[action]")]
    public class AjaxTestController : ControllerBase
    {
        [HttpPost]
        public IActionResult PostForm(string arg1, string arg2)
        {
            return ApiResult.Ok("arg1=" + arg1 + "&arg2=" + arg2);
        }

        [HttpPost]
        public IActionResult PostJson([FromBody]JToken json)
        {
            return ApiResult.Ok(json);
        }

        [HttpPost]
        public IActionResult PostText()
        {
            //asp.net.core.api 不支持 [FromBody]string，用 Request.GetBodyText() 代替
            var text = Request.GetBodyText();
            return ApiResult.Ok(text);
        }

        [HttpPost]
        public IActionResult PostNull()
        {
            return ApiResult.Ok();
        }
    }
}